package com.lagou.kudu;

import org.apache.kudu.client.*;

/**
 * @program: kuduHomework
 * @description:
 * @author: Mr.Wang
 * @create: 2021-03-05 12:21
 **/
public class UpdateKudu {
	public static void main(String[] args) {
		//地址
		String masterAddr = "node01";
		//创建客户端连接
		KuduClient client = new KuduClient.KuduClientBuilder(masterAddr)
				.defaultSocketReadTimeoutMs(6000).build();

		try {
			//获取表对象
			KuduTable table = client.openTable("student");
			//获取kudusession对象
			KuduSession kuduSession = client.newSession();
			//设置刷新及别
			kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
			kuduSession.setMutationBufferSpace(3000);

			//更新数据
			Update update = table.newUpdate();
			PartialRow row = update.getRow();
			row.addInt("id",1);
			row.addString("name","hello");
			kuduSession.apply(update);

			kuduSession.close();
		} catch (KuduException e) {
			e.printStackTrace();
		} finally {
			try {
				if (client != null) {
					client.close();
				}
			} catch (KuduException e) {
				e.printStackTrace();
			}
		}

	}
}
